package com.ctshk.sapp.order.custom.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.rpc.order.custom.dto.tourist.CustomOrderTouristCertificateDTO;
import com.ctshk.rpc.order.custom.req.tourist.CustomOrderTouristCertificateAddReq;
import com.ctshk.rpc.order.custom.req.tourist.CustomOrderTouristCertificateDeleteReq;
import com.ctshk.rpc.order.custom.req.tourist.CustomOrderTouristCertificateListReq;
import com.ctshk.rpc.order.custom.service.ICustomizedOrderTouristCertificateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 证件文件 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
@Api(value="证件文件", tags="证件文件")
@RestController
@Slf4j
@RequestMapping("/customized-order-tourist-certificate")
public class CustomizedOrderTouristCertificateController extends BaseController {

    @DubboReference
    private ICustomizedOrderTouristCertificateService orderTouristCertificateService;


    @ApiOperation(value = "上載證件", notes = "上載證件（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "旅客信息-上載證件", operDesc = "旅客信息-上載證件")
    @PostMapping("/upload")
    public Result upload(@RequestBody @Valid List<CustomOrderTouristCertificateAddReq> req) {
        try {
            return orderTouristCertificateService.upload(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "證件列表", notes = "證件列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "旅客信息-上传证件-查询", operDesc = "旅客信息-上传证件-查询")
    @PostMapping("/list")
    public Result<List<CustomOrderTouristCertificateDTO>> list(@RequestBody @Valid CustomOrderTouristCertificateListReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristCertificateService.list(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "删除", notes = "删除（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.DELETE, operTitle = "旅客信息-上传证件-删除", operDesc = "旅客信息-上传证件-删除")
    @PostMapping("/delete")
    public Result delete(@RequestBody @Valid CustomOrderTouristCertificateDeleteReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderTouristCertificateService.delete(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

}
